package ex.recruit.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import site.user.action.ApplyCommonStep;

public abstract class CommonApplyJudgment extends ApplyCommonStep {
	public static final String VIEW = "view";
	
	/**
	 * url参数未定义method时的默认Action函数. 默认为index Action.
	 */
	public ActionForward unspecified(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		return list(mapping, form, request, response);
	}
	
	/**
	 * 列出所有对象的Action函数.
	 */
	public abstract ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) ;
	
	/**
	 * 保存对象的Action函数.
	 */
	public ActionForward save(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		doInitEntity(request, form);

		doSaveEntity(request, form);

		return mapping.findForward(LIST);
	}

	/**
	 * view验证.
	 */
	public ActionForward viewValidator(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		initFirst(form, request);

		if (!validateEntity())
			return handleEntityMissing(mapping, form, request, response);
		return null;
	}

	/**
	 * 查看业务对象（不能修改）的Action函数.
	 */
	public ActionForward view(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {

		request.setAttribute(REQUEST_ENTITY, entity);

		return mapping.findForward(VIEW);
	}

}
